# -*- coding: utf-8 -*-
# @Time: 2021/8/13 14:34
# @File: problem-203.py
# @DESC:

from list_node_common import ListNode, listToNode


class Solution:
    def removeElements(self, head: ListNode, val: int) -> ListNode:
        cur = head
        newHead = ListNode(0)
        p = newHead
        while cur:
            if cur.val != val:
                p.next = ListNode(cur.val)
                p = p.next
            cur = cur.next

        return newHead.next

    def removeElementsV2(self, head: ListNode, val: int) -> ListNode:

        if head == None:
            return None
        p = head
        while p.next:
            if p.next.val == val:
                p.next = p.next.next
            else:
                p = p.next
        if head.val == val:
            return head.next
        return head


data = [7,7,7]

L = listToNode(data)

solution = Solution()
result = solution.removeElementsV2(L, 6)
print()
